package com.qujia.customer.controller;

import java.util.List;

import com.qujia.common.constant.HttpStatus;
import com.qujia.common.core.domain.entity.SysDept;
import com.qujia.common.core.domain.model.LoginUser;
import com.qujia.common.utils.SecurityUtils;
import com.qujia.system.service.ISysDeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.qujia.common.annotation.Log;
import com.qujia.common.core.controller.BaseController;
import com.qujia.common.core.domain.AjaxResult;
import com.qujia.common.enums.BusinessType;
import com.qujia.customer.domain.CustomerCardRecordRecharge;
import com.qujia.customer.service.ICustomerCardRecordRechargeService;
import com.qujia.common.utils.poi.ExcelUtil;
import com.qujia.common.core.page.TableDataInfo;

/**
 * 客户电子会员卡充值记录Controller
 * 
 * @author qujia
 * @date 2021-04-13
 */
@RestController
@RequestMapping("/customer/recharge")
public class CustomerCardRecordRechargeController extends BaseController
{
    @Autowired
    private ICustomerCardRecordRechargeService customerCardRecordRechargeService;
    @Autowired
    private ISysDeptService deptService;
    /**
     * 查询客户电子会员卡充值记录列表
     */
    @GetMapping("/list")
    public TableDataInfo list(CustomerCardRecordRecharge customerCardRecordRecharge)
    {
        LoginUser currentUser = SecurityUtils.getLoginUser();
        SysDept dept =new SysDept();
        dept.setDeptId(currentUser.getUser().getDeptId());
        List<String> list = deptService.selectDeptId(dept);
        if(list!=null && list.size()>0){
            customerCardRecordRecharge.setStationIdList(list);
            customerCardRecordRecharge.setStationId(null);
        }
        startPage();
        List<CustomerCardRecordRecharge> rechargeList = customerCardRecordRechargeService.selectCustomerCardRecordRechargeList(customerCardRecordRecharge);
        return getDataTable(rechargeList);
    }

    /**
     * 导出客户电子会员卡充值记录列表
     */
    @Log(title = "客户电子会员卡充值记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CustomerCardRecordRecharge customerCardRecordRecharge)
    {
        LoginUser currentUser = SecurityUtils.getLoginUser();
        SysDept dept =new SysDept();
        dept.setDeptId(currentUser.getUser().getDeptId());
        List<String> list = deptService.selectDeptId(dept);
        if(list!=null && list.size()>0){
            customerCardRecordRecharge.setStationIdList(list);
            customerCardRecordRecharge.setStationId(null);
        }
        List<CustomerCardRecordRecharge> rechargeList = customerCardRecordRechargeService.selectCustomerCardRecordRechargeList(customerCardRecordRecharge);
        ExcelUtil<CustomerCardRecordRecharge> util = new ExcelUtil<CustomerCardRecordRecharge>(CustomerCardRecordRecharge.class);
        return util.exportExcel(rechargeList, "recharge");
    }

    /**
     * 获取客户电子会员卡充值记录详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(customerCardRecordRechargeService.selectCustomerCardRecordRechargeById(id));
    }

    /**
     * 新增客户电子会员卡充值记录
     */
    @Log(title = "客户电子会员卡充值记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CustomerCardRecordRecharge customerCardRecordRecharge)
    {
        return toAjax(customerCardRecordRechargeService.insertCustomerCardRecordRecharge(customerCardRecordRecharge));
    }

    /**
     * 修改客户电子会员卡充值记录
     */
    @Log(title = "客户电子会员卡充值记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CustomerCardRecordRecharge customerCardRecordRecharge)
    {
        return toAjax(customerCardRecordRechargeService.updateCustomerCardRecordRecharge(customerCardRecordRecharge));
    }

    /**
     * 删除客户电子会员卡充值记录
     */
    @Log(title = "客户电子会员卡充值记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(customerCardRecordRechargeService.deleteCustomerCardRecordRechargeByIds(ids));
    }

    /**
     * 获取客户电子会员卡充值汇总金额
     */
    @GetMapping(value = "czAmtQuery")
    public AjaxResult czAmtQuery(CustomerCardRecordRecharge customerCardRecordRecharge)
    {
        LoginUser currentUser = SecurityUtils.getLoginUser();
        SysDept dept =new SysDept();
        dept.setDeptId(currentUser.getUser().getDeptId());
        List<String> list = deptService.selectDeptId(dept);
        if(list!=null && list.size()>0){
            customerCardRecordRecharge.setStationIdList(list);
            customerCardRecordRecharge.setStationId(null);
        }
        return AjaxResult.success(customerCardRecordRechargeService.czAmtQuery(customerCardRecordRecharge));
    }


    /**
     * 获取客户电子会员卡消费汇总折线图消费数据
     */
    @GetMapping(value = "listQydataCZ")
    public TableDataInfo listQydataCZ(CustomerCardRecordRecharge customerCardRecordRecharge)
    {
        LoginUser currentUser = SecurityUtils.getLoginUser();
        SysDept dept =new SysDept();
        dept.setDeptId(currentUser.getUser().getDeptId());
        List<String> list = deptService.selectDeptId(dept);
        if(list!=null && list.size()>0){
            customerCardRecordRecharge.setStationIdList(list);
            customerCardRecordRecharge.setStationId(null);
        }
        List<CustomerCardRecordRecharge> rechargelist =customerCardRecordRechargeService.listQydataCZ(customerCardRecordRecharge);
        return getTable(rechargelist);
    }
    @GetMapping("/selectCardDetail")
    public TableDataInfo selectCardDetail(CustomerCardRecordRecharge customerCardRecordRecharge)
    {
        LoginUser currentUser = SecurityUtils.getLoginUser();
        SysDept dept =new SysDept();
        dept.setDeptId(currentUser.getUser().getDeptId());
        List<String> list = deptService.selectDeptId(dept);
        if(list!=null && list.size()>0){
            customerCardRecordRecharge.setStationIdList(list);
            customerCardRecordRecharge.setStationId(null);
        }
        List<CustomerCardRecordRecharge> querylist = customerCardRecordRechargeService.selectCardDetail(customerCardRecordRecharge) ;
        List<CustomerCardRecordRecharge> pagelist = customerCardRecordRechargeService.selectCardDetailPage(customerCardRecordRecharge) ;
        TableDataInfo rspData = new TableDataInfo();
        rspData.setCode(HttpStatus.SUCCESS);
        rspData.setMsg("查询成功");
        rspData.setRows(querylist);
        rspData.setTotal(pagelist.size());
        return rspData;
    }

    @GetMapping(value = "/listCZData")
    public AjaxResult listCZData(CustomerCardRecordRecharge customerCardRecordRecharge)
    {
        LoginUser currentUser = SecurityUtils.getLoginUser();
        SysDept dept =new SysDept();
        dept.setDeptId(currentUser.getUser().getDeptId());
        List<String> list = deptService.selectDeptId(dept);
        if(list!=null && list.size()>0){
            customerCardRecordRecharge.setStationIdList(list);
            customerCardRecordRecharge.setStationId(null);
        }
        customerCardRecordRecharge.setStatus("1");
        return AjaxResult.success(customerCardRecordRechargeService.listCZData(customerCardRecordRecharge));
    }
}
